//title:
//url:
//onCloseAction
//width
//height
function createWindow(options){
	options = options||{};
	var title = options.title;
	var url = options.url||'';
	var titleColor = '#06b8ec';
	var width = options.width||'90%';
	var height = options.height || '90%';
	var data = options.data;
	var onBeforeHide=options.onBeforeHide;
	var onHidding=options.onHidding;
	var rootPane = $('<div class="s_wRoot" style="display:none;width:'+width+';height:'+height+'"></div>').appendTo($("body"));
	title = title||'';
	var titlePane = $('<div class="s_wTitle"></div>').appendTo(rootPane);
	var titleSpan = $('<span style="width:calc(100% - 80px)">'+title+'</span>').appendTo(titlePane);
	var closeSpan = $('<span>x</span>').appendTo(titlePane);
	var fullWinSpan = $('<span>□</span>').appendTo(titlePane);
	var contentPane = $('<div class="s_wContent"></div>').appendTo(rootPane);
	var frame = $('<iframe frameborder="no" width="100%" height="100%" marginwidth="0" marginheight="0" border="0" scrolling="auto" allowtransparency="yes"></iframe>').appendTo(contentPane);
	var loadingPane = $('<div style="position:absolute;margin:auto;width:350px;height:30px;top:0;bottom:0;left:0;right:0;z-index:99;"></div>').appendTo(contentPane)
	var coverPane = $('<div style="display:none;position:fixed;        top:0;bottom:0;right:0;left:0;background-color:rgba(255,255,255,0.5);z-index:99998;"></div>').appendTo($('body'));
	titlePane.bindMove({content:rootPane});
	titlePane.css('background-color',titleColor);
    var loadingObj = loadingPane.createProcess({space:1,width:350,height:30,val:-1,processColor:'#06b8ec',borderColor:'#06b8ec'});
	frame.load(function(e){
        loadingObj.setVal(1);
        loadingPane.remove();
        try{
            title = title||frame[0].contentDocument.title;
            titleSpan.text(title);
		}catch(e1){titleSpan.text("新页面");}
	});
	closeSpan.click(function(){
		if(typeof(options.onCloseAction) === 'function'){
			if(options.onCloseAction() === false){
				return;
			}
		}
		obj.destroy();
	});
	
	fullWinSpan.click(function(){
		if(full){
			full = false;
			rootPane.css('width',width);
			rootPane.css('height',height);
			rootPane.offset({top:offTop,left:offLeft});
		}else{
			full = true;
			offTop = rootPane.offset().top;
			offLeft = rootPane.offset().left;
			rootPane.css('top',0);
			rootPane.css('left',0);
			rootPane.css('bottom',0);
			rootPane.css('right',0);
			rootPane.css('width','auto');
			rootPane.css('height','auto');
		}
	});
	
	var full = false,offTop,offLeft;
	var isDestroy = false;
	var isShow = false;
	var isFirst = true;
	var animate;
	var explorer =navigator.userAgent ;
	var isIE = false;
	if (explorer.indexOf("MSIE") >= 0) {
		isIE = true;
	}
	var obj = {
		show:function(){
			if(isDestroy) return;
			if(isShow) return;
			var o = 0;
			var f = 10;
			var z = 0.5
			rootPane.css('opacity',0);
			rootPane.css('filter','blur(10px)')
			rootPane.show();
			coverPane.show();
			isShow = true;
			if(animate){
				clearInterval(animate);
			}
			animate = setInterval(function(){
				rootPane.css('opacity',o+=0.1);
				rootPane.css('zoom',z+=0.05);
				if(!isIE) rootPane.css('filter','blur('+(f--)+'px)');
				else rootPane.css('filter','progid:DXImageTransform.Microsoft.Blur(PixelRadius='+(f--)+', MakeShadow=false)');
				if(o >= 1){
					clearInterval(animate);
					rootPane.css('opacity','');
					rootPane.css('filter','');
					rootPane.css('zoom','');
					animate=undefined;
				}
			},50);
			if(isFirst){
				frame.attr('src',url);
				isFirst = false;
                top._contentData=top._contentData||[];
                var needcreate = true;
                for(var i in top._contentData){
                	var w = top._contentData[i];
                	if(w.win===frame[0].contentWindow){
                		w.data=data;
                		needcreate=false;
                		break;
					}
				}
				if(needcreate){
                    top._contentData.push({win:frame[0].contentWindow,data:data,winObj:this});
				}
			}
			return this;
		},
		hide:function(e){
			if(isDestroy) return;
			if(!isShow) return;
			if(typeof(onBeforeHide)==='function'){
				var before = onBeforeHide.call(this);
				if(before === false){
					return this;
				}
			}
			var o = 1;
			var f = 0;
			var z = 1;
			isShow = false;
            if(animate){
                clearInterval(animate);
            }
			animate = setInterval(function(){
				rootPane.css('opacity',o-=0.1);
				rootPane.css('zoom',z-=0.05);
				if(!isIE)rootPane.css('filter','blur('+(f++)+'px)');
				else rootPane.css('filter','progid:DXImageTransform.Microsoft.Blur(PixelRadius='+(f++)+', MakeShadow=false)');
				if(o <= 0){
					clearInterval(animate);
					rootPane.hide();
					rootPane.css('opacity','');
					rootPane.css('filter','');
					rootPane.css('zoom','');
					coverPane.hide();
					if(typeof(e)==='function') e();
					animate=undefined;
				}
			},50);
            if(typeof(onHidding)==='function'){
                onHidding.call(this);
            }
			return this;
		},
		destroy:function(){
			if(isDestroy) return;
			this.hide(function(){
				titlePane.unbindMove();
				rootPane.remove();
				coverPane.remove();
				isDestroy = true;
			});
            for(var i in top._contentData) {
                var w = top._contentData[i];
                if (w.win === frame[0].contentWindow) {
					top._contentData.splice(i,1);
					break;
                }
            }
		}
	};
	return obj;
}